#include<vector>
#include<stdio.h>
#include<string>
#include<iostream>
using namespace std;
class Timu{
public:
	int perfectScore;
	int optionsNum;
	vector<char> ans;
	Timu(){};
};
int cuowucishu[100];
int main() {

	int n,m;
	scanf("%d%d",&n,&m);
	vector<Timu*> timus;
	for(int i=0;i<m;i++){
		Timu* timu = new Timu();
		int t;
		scanf("%d%d%d",&timu->perfectScore,&timu->optionsNum,&t);
		while(t-->0){
			char rightchar;
			scanf(" %c",&rightchar);
			timu->ans.push_back(rightchar);
		}
		timus.push_back(timu);
	}

    /*
	printf("=======================\n");
	for(int i=0;i<timus.size();i++){
        Timu* timu = timus[i];
        printf("%d %d",timu->perfectScore,timu->optionsNum);
        for(int j=0;j<timu->ans.size();j++){
            printf(" %c",timu->ans[j]);
        }
        printf("\n");
	}
	printf("=======================\n");
	*/


	bool toosimple = true;
    getchar();

    vector<string> answers;
	for(int i=0;i<n;i++){
        string answer;
		getline(cin,answer);
		//printf("%s\n",answer.c_str());
		answers.push_back(answer);
	}
	for(int i=0;i<answers.size();i++){
        string answer=answers[i];

		int totalScore = 0;
        int timuId = -1;
        int startIndx=0;
        int endIndx=0;
        while((startIndx = answer.find_first_of('(', startIndx))!=string::npos){
            endIndx = answer.find_first_of(')',startIndx);
            string timustr = answer.substr(startIndx+1,endIndx-startIndx-1);
            startIndx=endIndx;
            timuId++;
            //cout<<timustr<<endl;
            bool isTimuRight=true;
            int options = timustr[0]-'0';
            //cout<<"options:"<<options<<" ans.size():"<<timus[timuId]->ans.size()<<endl;
            if(options != timus[timuId]->ans.size()){
                cuowucishu[timuId]++;
                toosimple=false;
                isTimuRight=false;
            }else{
                for(int k=0;k<options;k++){
                    if(timustr[2*k+2]!=timus[timuId]->ans[k]){
                        cuowucishu[timuId]++;
                        toosimple=false;
                        isTimuRight=false;
                        break;
                    }
                }
            }
            if(isTimuRight)
                totalScore+=timus[timuId]->perfectScore;
        }

        printf("%d\n",totalScore);
	}


	if(toosimple){
		printf("Too simple");
	}else{
		vector<int> timuIds;
		timuIds.push_back(0);
		int maxWrong=cuowucishu[0];
		for(int i=1;i<m;i++){
			if(maxWrong<cuowucishu[i]){
				timuIds.clear();
				maxWrong=cuowucishu[i];
				timuIds.push_back(i);
			}else if(maxWrong==cuowucishu[i]){
				timuIds.push_back(i);
			}
		}
		printf("%d",maxWrong);
		for(int i=0;i<timuIds.size();i++){
			printf(" %d",timuIds[i]+1);
		}
		printf("\n");
	}

	return 0;
}
